package com.dongxing.concyrrency.chapter4;

import java.util.concurrent.TimeUnit;

/**
 * @author XavierDong
 **/
public class DaemonThread2 {

    public static void main(String[] args) {

        Thread t = new Thread(() -> {

            Thread innerThread = new Thread(() -> {
                try {
                    while (true) {
                        System.out.println("do some thing for health check.");
                        TimeUnit.SECONDS.sleep(10);
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    Thread.currentThread().interrupt();
                }
            });
            innerThread.setDaemon(true);
            innerThread.start();

            try {
                TimeUnit.SECONDS.sleep(1);
                System.out.println("T Thread finish done.");
            } catch (InterruptedException e) {
                e.printStackTrace();
                Thread.currentThread().interrupt();
            }
        });
//        t.setDaemon(true);
        t.start();
    }
}
